package com.chuangke.sinotrukbudget.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.core.http.HttpResult;
import com.chuangke.sinotrukbudget.domain.BudgetDeptAccountSaveDto;
import com.chuangke.sinotrukbudget.service.BudgetDeptAccountService;

/**
 * 部门科目对照 Controller
 * 
 * @author chuangke
 * @date "2022-10-21"
 */
@RestController
@RequestMapping("/budget/deptaccount")
public class BudgetDeptAccountController {

	@Autowired
	private BudgetDeptAccountService budgetDeptAccountService;

	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/save")
	public HttpResult save(@RequestBody BudgetDeptAccountSaveDto params) {
		return HttpResult.ok(budgetDeptAccountService.save(params.getDeptId(), params.getDatas()));
	};

	@SuppressWarnings("unchecked")
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/delete")
	public HttpResult delete(@RequestBody Map<String, Object> params) {
		String deptId = (String) params.get("deptId");
		List<String> ids = (List<String>) params.get("ids");
		return HttpResult.ok(budgetDeptAccountService.delete(deptId, ids));
	};

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/list/{type}")
	public HttpResult listByDept(@PathVariable("type") String deptId) {
		return HttpResult.ok(budgetDeptAccountService.listByDept(deptId));
	};
	
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping(value = "/find")
	public HttpResult find(@RequestBody Map<String, Object> params) {
		String deptId = (String)params.get("deptId") ;
		String name = (String)params.get("name") ;
		return HttpResult.ok(budgetDeptAccountService.listByDept(deptId,name));
	};
	
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/listowncompyguikou")
	public HttpResult listUserOwnCompyGuikou() {
		return HttpResult.ok(budgetDeptAccountService.listUserOwnCompyGuikou());
	};

}
